package myself.a000util;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.*;

import static myself.a000util.NodeCollection.DoubleNode;
import static myself.a000util.NodeCollection.SingleNode;

/**
 * @author 叶之越
 * Description
 * Date 2021/1/20
 * Time 19:57
 * Mail 739153436@qq.com
 */
public class Logarithm {

    /**
     * 获取随机数组
     */
    public static int[] getRandomArr(int low, int high, int length) {
        int difference = high - low;
        int[] arr = new int[length];
        for (int i = 0; i < length; i++) {
            arr[i] = low + (int) (Math.random() * difference + 1);
        }
        return arr;
    }

    /**
     * 常用测试用例
     */
    public static <T> void check(Class<T> c, String methodName) {
        check(c, methodName, -100, 100, 20, false);
    }

    public static <T> void check(Class<T> c, String methodName, boolean printAll) {
        check(c, methodName, -100, 100, 20, printAll);
    }

    /**
     * 参数完全测试用例
     */
    public static <T> void check(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
        System.out.println("Check is beginning !");
        try {
            // 准备测试数据
            Constructor<T> constructor = c.getConstructor();
            T obj = constructor.newInstance();
            Method sort = c.getMethod(methodName, int[].class);
            // 循环测试
            for (int i = 0; i < 10000; i++) {
                int arrLength = (int) (Math.random() * randomArrMaxLength) + 1;
                int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);
                int[] newArr = new int[randomArr.length];
                int[] debugArr = new int[randomArr.length];
                for (int j = 0; j < randomArr.length; j++) {
                    newArr[j] = randomArr[j];
                    debugArr[j] = randomArr[j];
                }
                // 正确无误的对照排序数组
                Arrays.sort(newArr);
                // 自己的排序代码
                sort.invoke(obj, randomArr);
                for (int j = 0; j < randomArr.length; j++) {
                    if (newArr[j] != randomArr[j]) {
                        // 打印错误序号
                        System.out.print("\nFalse: ");
                        Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                        System.out.print("\n Ture: ");
                        Arrays.stream(newArr).forEach(value -> System.out.print(value + ","));
                        // 可以再次错误重现，我们来进行Debug
                        sort.invoke(obj, debugArr);
                        System.out.println("\nFail !");
                        break;
                    }
                    if (printAll) {
                        System.out.print("\nFalse: ");
                        Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                        System.out.print("\n Ture: ");
                        Arrays.stream(newArr).forEach(value -> System.out.print(value + ","));
                    }
                }
                if (i == 9999) {
                    System.out.println("\nSuccessful !");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 二分查找相关题对数器
     */
    public static class BS {
        public static <T> void checkBSExit(Class<T> c, String methodName) {
            checkBSExit(c, methodName, -100, 100, 20, false);
        }

        public static <T> void checkBSExit(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, int[].class, int.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * randomArrMaxLength) + 1;
                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);
                    Arrays.sort(randomArr);
                    // 自己的排序代码
                    int num = randomArrMin + (int) (Math.random() * (randomArrMax - randomArrMin) + 1);
                    Boolean result = (Boolean) sort.invoke(obj, randomArr, num);
                    for (int j = 0; j < randomArr.length; j++) {
                        if (randomArr[j] == num && result == false) {
                            System.out.print("\nFalse: ");
                            Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                            System.out.println("\nFail !");
                            break;
                        }
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public static <T> void checkBSLeft(Class<T> c, String methodName) {
            checkBSLeft(c, methodName, -100, 100, 20, false);
        }

        public static <T> void checkBSLeft(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, int[].class, int.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * randomArrMaxLength) + 1;
                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);
                    Arrays.sort(randomArr);
                    // 自己的排序代码
                    int num = randomArrMin + (int) (Math.random() * (randomArrMax - randomArrMin) + 1);
                    Integer result = (Integer) sort.invoke(obj, randomArr, num);
                    for (int j = 0; j < randomArr.length; j++) {
                        if (randomArr[j] >= num) {
                            if (result.equals(j)) {
                                break;
                            }
                            System.out.print("\nFalse: num is " + num + " and ");
                            Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                            sort.invoke(obj, randomArr, num);
                            System.out.println("\nFail !");
                            throw new Exception();
                        }
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public static <T> void checkBSRight(Class<T> c, String methodName) {
            checkBSRight(c, methodName, -100, 100, 20, false);
        }

        public static <T> void checkBSRight(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, int[].class, int.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * randomArrMaxLength) + 1;
                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);
                    Arrays.sort(randomArr);
                    // 自己的排序代码
                    int num = randomArrMin + (int) (Math.random() * (randomArrMax - randomArrMin) + 1);
                    Integer result = (Integer) sort.invoke(obj, randomArr, num);
                    for (int j = randomArr.length - 1; j >= 0; j--) {
                        if (randomArr[j] <= num) {
                            if (result.equals(j)) {
                                break;
                            }
                            System.out.print("\nFalse: num is " + num + " and ");
                            Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                            sort.invoke(obj, randomArr, num);
                            System.out.println("\nFail !");
                            throw new Exception();
                        }
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 异或运算符相关题对数器
     */
    public static class XOR {
        public static <T> void check(Class<T> c, String methodName) {
            check(c, methodName, -100, 100, 20, false);
        }

        public static <T> void check(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, int[].class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    List<Integer> list = new ArrayList<>();
                    int odd1 = (int) (Math.random() * 100);
                    // 添加奇数次奇数
                    odd1 = odd1 % 2 == 0 ? odd1 + 1 : odd1;
                    for (int j = 0; j < odd1; j++) {
                        list.add(odd1);
                    }
                    int odd2 = (int) (Math.random() * 100);
                    // 添加奇数次奇数
                    odd2 = odd2 % 2 == 0 ? odd2 + 1 : odd2;
                    odd2 = odd2 == odd1 ? odd2 + 2 : odd2;
                    for (int j = 0; j < odd2; j++) {
                        list.add(odd2);
                    }

                    int evenNum = 50 + (int) (Math.random() * 50);
                    for (int j = 0; j < evenNum; j++) {
                        int even = (int) (Math.random() * 100);
                        even = even % 2 == 0 ? even : even + 1;
                        for (int k = 0; k < even; k++) {
                            list.add(even);
                        }
                    }

                    int[] randomArr = new int[list.size()];
                    Collections.shuffle(list);
                    for (int j = 0; j < list.size(); j++) {
                        randomArr[j] = list.get(j);
                    }

                    int[] result = (int[]) sort.invoke(obj, randomArr);
                    if ((result[0] == odd1 && result[1] == odd2)
                            || (result[1] == odd1 && result[0] == odd2)) {
                    } else {
                        System.out.println("\n Faile");
                        System.out.println("list size is : " + list.size() + "\n" + "odd num is : " + odd1 + "--" + odd2);
                        int[] debug = (int[]) sort.invoke(obj, randomArr);
                        throw new Exception();
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 栈和队列相关对数器
     */
    public static class NodeList {
        public static <T> void checkSingleReverse(Class<T> c, String methodName) {
            checkSingleReverse(c, methodName, -100, 100, 20, false);
        }

        public static <T> void checkSingleReverse(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, SingleNode.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * (randomArrMaxLength + 1));


                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);

                    SingleNode<Integer> testNode = null;
                    SingleNode<Integer> debugNode = null;

                    SingleNode<Integer> testNodeCur = null;
                    SingleNode<Integer> debugNodeCur = null;
                    List<Integer> correct = new ArrayList<>();
                    for (int j = 0; j < randomArr.length; j++) {
                        correct.add(randomArr[j]);
                        if (j == 0) {
                            testNode = new SingleNode<>(randomArr[j]);
                            debugNode = new SingleNode<>(randomArr[j]);
                            testNodeCur = testNode;
                            debugNodeCur = debugNode;
                        }
                        if (j != 0) {
                            testNodeCur.next = new SingleNode(randomArr[j]);
                            testNodeCur = testNodeCur.next;
                            debugNodeCur.next = new SingleNode(randomArr[j]);
                            debugNodeCur = debugNodeCur.next;
                        }
                    }


                    // 自己的排序代码
                    SingleNode result = (SingleNode) sort.invoke(obj, testNode);

                    Collections.reverse(correct);

                    for (int j = 0; j < correct.size(); j++) {
                        if (!correct.get(j).equals(result.t)) {
                            System.out.print("\nFalse: ");
                            int count = 0;
                            while (result != null && count < correct.size()) {
                                count++;
                                System.out.print(result.t + ",");
                                result = result.next;
                            }
                            System.out.print("\n Ture: ");
                            correct.forEach(value -> System.out.print(value + ","));
                            SingleNode debug = (SingleNode) sort.invoke(obj, debugNode);
                            throw new Exception();
                        }
                        result = result.next;
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public static <T> void checkDoubleReverse(Class<T> c, String methodName) {
            checkDoubleReverse(c, methodName, -100, 100, 20, false);
        }

        public static <T> void checkDoubleReverse(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, DoubleNode.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * (randomArrMaxLength + 1));


                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);

                    DoubleNode<Integer> testNode = null;
                    DoubleNode<Integer> debugNode = null;

                    DoubleNode<Integer> testNodeCur = null;
                    DoubleNode<Integer> debugNodeCur = null;
                    DoubleNode<Integer> testNodePre = null;
                    DoubleNode<Integer> debugNodePre = null;
                    List<Integer> correct = new ArrayList<>();
                    for (int j = 0; j < randomArr.length; j++) {
                        correct.add(randomArr[j]);
                        if (j == 0) {
                            testNode = new DoubleNode<>(randomArr[j]);
                            debugNode = new DoubleNode<>(randomArr[j]);
                            testNodeCur = testNode;
                            debugNodeCur = debugNode;
                        }
                        if (j != 0) {
                            testNodePre = testNodeCur;
                            testNodeCur.next = new DoubleNode(randomArr[j]);
                            testNodeCur = testNodeCur.next;
                            testNodeCur.pre = testNodePre;

                            debugNodePre = debugNodeCur;
                            debugNodeCur.next = new DoubleNode(randomArr[j]);
                            debugNodeCur = debugNodeCur.next;
                            debugNodeCur.pre = debugNodePre;
                        }
                    }


                    // 自己的排序代码
                    DoubleNode result = (DoubleNode) sort.invoke(obj, testNode);

                    Collections.reverse(correct);

                    // next 指针对数
                    for (int j = 0; j < correct.size(); j++) {
                        if (!correct.get(j).equals(result.t)) {
                            System.out.print("\nFalse: ");
                            int count = 0;
                            while (result != null && count < correct.size()) {
                                count++;
                                System.out.print(result.t + ",");
                                result = result.next;
                            }
                            System.out.print("\n Ture: ");
                            correct.forEach(value -> System.out.print(value + ","));
                            SingleNode debug = (SingleNode) sort.invoke(obj, debugNode);
                            throw new Exception();
                        }
                        if (j != correct.size() - 1) result = result.next;
                    }

                    // pre 指针对数
                    for (int j = correct.size() - 1; j >= 0; j--) {
                        if (!correct.get(j).equals(result.t)) {
                            System.out.print("\nFalse: ");
                            int count = 0;
                            while (result != null && count < correct.size()) {
                                count++;
                                System.out.print(result.t + ",");
                                result = result.next;
                            }
                            System.out.print("\n Ture: ");
                            correct.forEach(value -> System.out.print(value + ","));
                            SingleNode debug = (SingleNode) sort.invoke(obj, debugNode);
                            throw new Exception();
                        }
                        result = result.pre;
                    }

                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public static <T> void checkSingleRemove(Class<T> c, String methodName) {
            checkSingleRemove(c, methodName, -100, 100, 20, false);
        }

        public static <T> void checkSingleRemove(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, SingleNode.class, int.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * (randomArrMaxLength + 1));


                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);

                    SingleNode<Integer> testNode = new SingleNode<>();
                    SingleNode<Integer> debugNode = null;

                    SingleNode<Integer> testNodeCur = new SingleNode<>();
                    SingleNode<Integer> debugNodeCur = null;
                    List<Integer> correct = new ArrayList<>();
                    for (int j = 0; j < randomArr.length; j++) {
                        correct.add(randomArr[j]);
                        if (j == 0) {
                            testNode = new SingleNode<>(randomArr[j]);
                            debugNode = new SingleNode<>(randomArr[j]);
                            testNodeCur = testNode;
                            debugNodeCur = debugNode;
                        }
                        if (j != 0) {
                            testNodeCur.next = new SingleNode(randomArr[j]);
                            testNodeCur = testNodeCur.next;
                            debugNodeCur.next = new SingleNode(randomArr[j]);
                            debugNodeCur = debugNodeCur.next;
                        }
                    }


                    // 自己的排序代码
                    int removeObj = (int) (Math.random() * (randomArr.length + 1));
                    SingleNode result = null;
                    try {
                        result = (SingleNode) sort.invoke(obj, testNode, removeObj);
                    } catch (Exception e) {
                        result = (SingleNode) sort.invoke(obj, testNode, removeObj);
                        e.printStackTrace();
                    }
                    Iterator<Integer> it = correct.listIterator();
                    while (it.hasNext()) {
                        if (it.next().equals(removeObj)) {
                            it.remove();
                        }
                    }
                    int size = 0;
                    SingleNode cur = result;
                    while (cur != null) {
                        cur = cur.next;
                        size++;
                    }
                    for (int j = 0; j < correct.size(); j++) {
                        if (correct.size() != size) {
                            System.out.println(size);
                        }
                        if (result != null && !correct.get(j).equals(result.t)) {
                            System.out.print("\nFalse: ");
                            int count = 0;
                            while (result != null && count < correct.size()) {
                                count++;
                                System.out.print(result.t + ",");
                                result = result.next;
                            }
                            System.out.print("\n Ture: ");
                            correct.forEach(value -> System.out.print(value + ","));
                            SingleNode debug = (SingleNode) sort.invoke(obj, debugNode, removeObj);
                            throw new Exception();
                        }
                        result = result.next;
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class MergeSort {
        public static <T> void check(Class<T> c, String methodName) {
            check(c, methodName, -100, 100, 20, false);
        }

        public static <T> void check(Class<T> c, String methodName, boolean printAll) {
            check(c, methodName, -100, 100, 20, printAll);
        }

        public static <T> void check(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, int[].class, int.class, int.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * randomArrMaxLength);
                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);
                    int[] newArr = new int[randomArr.length];
                    int[] debugArr = new int[randomArr.length];
                    for (int j = 0; j < randomArr.length; j++) {
                        newArr[j] = randomArr[j];
                        debugArr[j] = randomArr[j];
                    }
                    // 正确无误的对照排序数组
                    Arrays.sort(newArr);
                    // 自己的排序代码
                    sort.invoke(obj, randomArr, 0, randomArr.length - 1);
                    for (int j = 0; j < randomArr.length; j++) {
                        if (newArr[j] != randomArr[j]) {
                            // 打印错误序号
                            System.out.print("\nFalse: ");
                            Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                            System.out.print("\n Ture: ");
                            Arrays.stream(newArr).forEach(value -> System.out.print(value + ","));
                            // 可以再次错误重现，我们来进行Debug
                            sort.invoke(obj, debugArr, 0, debugArr.length - 1);
                            System.out.println("\nFail !");
                            break;
                        }
                        if (printAll) {
                            System.out.print("\nFalse: ");
                            Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                            System.out.print("\n Ture: ");
                            Arrays.stream(newArr).forEach(value -> System.out.print(value + ","));
                        }
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public static <T> void checkSmallSum(Class<T> c, String methodName) {
            checkSmallSum(c, methodName, -100, 100, 20, false);
        }

        public static <T> void checkSmallSum(Class<T> c, String methodName, boolean printAll) {
            checkSmallSum(c, methodName, -100, 100, 20, printAll);
        }

        public static <T> void checkSmallSum(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, int[].class, int.class, int.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * randomArrMaxLength);
                    int[] testArr = getRandomArr(randomArrMin, randomArrMax, arrLength);
                    int[] correctArr = new int[testArr.length];
                    int[] debugArr = new int[testArr.length];
                    for (int j = 0; j < testArr.length; j++) {
                        correctArr[j] = testArr[j];
                        debugArr[j] = testArr[j];
                    }
                    // 正确无误的对照排序数组
                    int correct = 0;
                    for (int j = 0; j < correctArr.length; j++) {
                        for (int k = j; k < correctArr.length; k++) {
                            if (correctArr[j] < correctArr[k]) {
                                correct += correctArr[j];
                            }
                        }
                    }
                    // 自己的排序代码
                    int result = (int) sort.invoke(obj, testArr, 0, testArr.length - 1);

                    if (correct != result) {
                        // 打印错误序号
                        System.out.print("\nFalse: " + result + "\n");
                        Arrays.stream(testArr).forEach(value -> System.out.print(value + ","));
                        System.out.print("\n Ture: " + correct + "\n");
                        Arrays.stream(correctArr).forEach(value -> System.out.print(value + ","));
                        // 可以再次错误重现，我们来进行Debug
                        sort.invoke(obj, debugArr, 0, debugArr.length - 1);
                        System.out.println("\nFail !");
                        break;
                    }
                    if (printAll) {
                        System.out.print("\nFalse: ");
                        Arrays.stream(testArr).forEach(value -> System.out.print(value + ","));
                        System.out.print("\n Ture: ");
                        Arrays.stream(correctArr).forEach(value -> System.out.print(value + ","));
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class QuickSort {
        public static <T> void check(Class<T> c, String methodName) {
            check(c, methodName, -100, 100, 20, false);
        }

        public static <T> void check(Class<T> c, String methodName, boolean printAll) {
            check(c, methodName, -100, 100, 20, printAll);
        }

        public static <T> void check(Class<T> c, String methodName, int randomArrMin, int randomArrMax, int randomArrMaxLength, boolean printAll) {
            System.out.println("Check is beginning !");
            try {
                // 准备测试数据
                Constructor<T> constructor = c.getConstructor();
                T obj = constructor.newInstance();
                Method sort = c.getMethod(methodName, int[].class, int.class, int.class);
                // 循环测试
                for (int i = 0; i < 10000; i++) {
                    int arrLength = (int) (Math.random() * randomArrMaxLength);
                    int[] randomArr = getRandomArr(randomArrMin, randomArrMax, arrLength);
                    int[] newArr = new int[randomArr.length];
                    int[] debugArr = new int[randomArr.length];
                    for (int j = 0; j < randomArr.length; j++) {
                        newArr[j] = randomArr[j];
                        debugArr[j] = randomArr[j];
                    }
                    // 正确无误的对照排序数组
                    Arrays.sort(newArr);
                    // 自己的排序代码
                    sort.invoke(obj, randomArr, 0, randomArr.length - 1);
                    for (int j = 0; j < randomArr.length; j++) {
                        if (newArr[j] != randomArr[j]) {
                            // 打印错误序号
                            System.out.print("\nFalse: ");
                            Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                            System.out.print("\n Ture: ");
                            Arrays.stream(newArr).forEach(value -> System.out.print(value + ","));
                            // 可以再次错误重现，我们来进行Debug
                            sort.invoke(obj, debugArr, 0, debugArr.length - 1);
                            System.out.println("\nFail !");
                            break;
                        }
                        if (printAll) {
                            System.out.print("\nFalse: ");
                            Arrays.stream(randomArr).forEach(value -> System.out.print(value + ","));
                            System.out.print("\n Ture: ");
                            Arrays.stream(newArr).forEach(value -> System.out.print(value + ","));
                        }
                    }
                    if (i == 9999) {
                        System.out.println("\nSuccessful !");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
